package MyQueue;

import org.junit.Test;

/**
 * @author yyq
 * @create 2021-09-17 12:17
 * 数组创建队列
 */
public class MyQueue {
    private int maxSize;
    private int low;
    private int high;
    private Object array[];
    private int length;

    public MyQueue(int maxSize){
        this.maxSize=maxSize;
        low=0;
        high=0;
        length=0;
        array=new Object[maxSize];
    }

    public void Into(Object ob ){
        if(high<maxSize){
            array[high]=ob;
            high++;
            length++;
        }
        else {
            System.out.println("队列空间不足");
        }

    }

    public Object Out(){
        if(low<high) {
            low++;
            length--;
            return array[low-1];
        }
        if(low==high){
           if(length==0) System.out.println("为空哦");
           else {
               int tmp=low;
               low=0;
               high=0;
               return array[tmp];
           }
        }
        return 404;
    }

    public static void main(String[] args) {

            MyQueue myQueue=new MyQueue(10);
            myQueue.Into(10);
            myQueue.Into(20);
            System.out.println(myQueue.Out());
            System.out.println(myQueue.Out());
            System.out.println(myQueue.Out());


    }

}

